package org.grottarossa.ui.core.casemanagement.contents;

import java.io.IOException;

import com.vaadin.Application;
import com.vaadin.terminal.StreamResource;
import com.vaadin.ui.Embedded;

public class DocumentViewer {

	private static final String RAW        = "application/octet-stream";
    private static final String EXCEL      = "application/vnd.ms-excel";
    private static final String HTML       = "text/html";
    private static final String PDF        = "application/pdf";
    private static final String POWERPOINT = "application/vnd.ms-powerpoint";
    private static final String RTF        = "application/rtf";
    private static final String PLAINTEXT  = "text/plain";
    private static final String WORD       = "application/msword";
    private static final String XML        = "application/xml";
    private static final String OPENOFFICE = "application/vnd.oasis.opendocument.text";

	public Embedded showDocument(Application application,byte[] documentEssence) {

		DocumentStreamResource documentStreamResource = new DocumentStreamResource(documentEssence);
		StreamResource sr = new StreamResource(documentStreamResource, "test.pdf", application);
		sr.setCacheTime(10000);
		sr.setMIMEType(PDF);
		try {
			sr.getStream().getStream().close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Embedded c = new Embedded("Document",sr);
		c.setMimeType(PDF);
		c.setType(Embedded.TYPE_BROWSER);
		c.setWidth("800px");
		c.setHeight("700px");
		return c;
	}

}
